package cc.vv.btpartyjob.jnimodule.delegate

import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.TextView
import cc.vv.baselibrary.util.ColorUtil
import cc.vv.btpartyjob.jnimodule.R
import cc.vv.btpartyjob.jnimodule.adapter.DataListAdapter
import cc.vv.btpartyjob.jnimodule.moudel.bean.NewsBean
import cc.vv.mvp.delegate.BaseAppDelegate
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 活动列表托管类
 * Created by Chen.qi on 2018/10/30.
 */
class JniDataListFragmentDelegate : BaseAppDelegate() {

    override fun initWidget() {

    }

    override fun initLayoutRes(): Int {
        return R.layout.fragment_data_list
    }


    /**
     * 设置刷新监听
     */
    fun bindRefreshListener(listener: SwipeRefreshLayout.OnRefreshListener) {
        val refresh = getView<SwipeRefreshLayout>(R.id.srl_fdl_swipeJniLayout)
        refresh?.setOnRefreshListener(listener)
        refresh?.setColorSchemeColors(ColorUtil.setBCColor(R.color.color_FA555C))
    }

    /**
     * 设置刷新停止
     */
    fun stopRefreshing() {
        val refresh = getView<SwipeRefreshLayout>(R.id.srl_fdl_swipeJniLayout)
        refresh?.isRefreshing = false
    }

    /**
     * 设置加载更多监听
     */
    fun bindLoadMore(mAdapter: DataListAdapter?, loadMoreListener: BaseQuickAdapter.RequestLoadMoreListener) {
        val recyclerView = getView<RecyclerView>(R.id.rv_fdl_dataList)
        if (null != recyclerView) {
            mAdapter?.setOnLoadMoreListener(loadMoreListener, recyclerView)
        }
    }


    /** 设置适配器数据*/
    fun setRecyclerViewAdapter(mAdapter: DataListAdapter?) {
        if (null != mAdapter) {
            val recyclerView = getView<RecyclerView>(R.id.rv_fdl_dataList)
            recyclerView?.layoutManager = LinearLayoutManager(context)
            recyclerView?.adapter = mAdapter
        }
    }

    /** 设置适配器数据*/
    fun setAdapterData(mAdapter: DataListAdapter?, list: List<NewsBean>?) {
        if (null != list) {
            mAdapter?.setNewData(list)
            if (list.isEmpty()) {
                showNoData(true)
            } else {
                showNoData(false)
            }
        } else {
            showNoData(true)
        }
    }

    private fun showNoData(isShow: Boolean) {
        val noData = getView<TextView>(R.id.btv_fdl_noData)
        if (isShow) {
            noData?.visibility = View.VISIBLE
        } else {
            noData?.visibility = View.GONE
        }
    }

}